package com.hyh.proxy.protect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import com.hyh.proxy.model.PersonBean;

public class ProxyFactory {

	private Object obj;
	
	public ProxyFactory(Object obj) {
		this.obj = obj;
	}
	
	public PersonBean getProxyInstance(){
		return (PersonBean)Proxy.newProxyInstance(obj.getClass().getClassLoader(),
				               obj.getClass().getInterfaces(), 
				               new InvocationHandler() {
								
								@Override
								public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
									if(method.getName().equals("setHotOrNotRating")){
										throw new IllegalAccessException();
									}else{
										return method.invoke(obj, args);
									}
								}
							   }
				               );
	}

}
